from models.model import *
from models.notice_info import *

class Notice(db.Model):
    __tablename__ = "notice"
    __table_args__ = {'mysql_collate': 'utf8_general_ci'}
    notice_id = db.Column(db.String(64), primary_key=True)
    notice_title = db.Column(db.String(256), nullable=False)
    notice_detail = db.Column(db.String(1000), nullable=False)
    notice_view_count = db.Column(db.String(10), nullable=False)
    notice_url = db.Column(db.String(1000), nullable=False)
    notice_image = db.Column(db.String(1000), nullable=False)
    if_admin = db.Column(db.Boolean, default=False)



def create_item(notice_id, notice_title, notice_detail, notice_view_count, notice_url, notice_image):
    return Notice(notice_id=notice_id, 
                  notice_title=notice_title, 
                  notice_detail=notice_detail, 
                  notice_view_count=notice_view_count, 
                  notice_url=notice_url,
                  notice_image=notice_image
                )

def initial_notice():
    try:
        
        notices = []
        for info in defaulInfo:
            print("123",info)
            notices.append(create_item(info[0],info[1],info[2],info[3],info[4],info[5]))
        db.session.add_all(notices)
        db.session.commit()
    except Exception as e:
        print('err', e)

def show_all_notice():
    notices = Notice.query.filter(Notice.if_admin == False).all()
    re = []
    for student in notices:
        re.append(student)
    return re
